<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" lang="ru" xml:lang="ru"> 
    <head>
	<title>LocalCRM</title>
	<script src="js/jquery-1.4.2.min.js" type="text/javascript"></script>
	<script src="js/jquery-ui-1.8.4.custom.min.js" type="text/javascript"></script>
	<script src="js/jquery.blockUI.js" type="text/javascript"></script>
	<script src="js/crm/common.js" type="text/javascript"></script>
	<link href="css/redmond/jquery-ui-1.8.4.custom.css" rel="stylesheet" type="text/css"/>

	<script src="js/i18n/grid.locale-ru.js" type="text/javascript"></script>
	<script src="js/jquery.jqGrid.min.js" type="text/javascript"></script>
	<link href="css/ui.jqgrid.css" rel="stylesheet" type="text/css"/>
    </head>
    <body>
	<a href="user-logout.php" class="button" style="position: absolute; margin-top: 7px; right: 14px; z-index: 999;">Выход</a>

	<div class="tabs">
	    <ul>
		<li><a href="#info">Карточка</a></li>
		<!--<li><a href="#bank">Реквизиты</a></li> -->
		<!--<li><a href="#contact">Контакты</a></li>-->
	    {if $services|@count>0}
		<li><a href="#services">Услуги</a></li>
	    {/if}
		<!--<li><a href="#document">Документы</a></li>-->
	    {if $docs|@count>0}
		<li><a href="#invoice">Счета</a></li>
	    {/if}
	    </ul>
	    <div id="info">
		<table align="center" class="ui-widget">
		    <tr>
			<td align="right">Клиент:</td>
			<td colspan="3">{$customer.customer_name|sslash}</td>
		    </tr>
		    {foreach from=$contracts item=c}
		    <tr>
			<td align="right">Договор c <strong>{$c.executive_name|sslash}</strong>:</td>
			<td colspan="3"><strong>{$c.contract_number}</strong>{if $c.accepted_date!=''} от {$c.accepted_date|date_format:'%d.%m.%Y'}{/if}</td>
			<td colspan="1">Баланс: {$c.balance}</td>
			<td colspan="1">Аванс: {$c.prepayment}</td>
		    </tr>
		    {/foreach}
		    {if $manager!=''}
		    <tr>
			<td align="right">Ваш менеджер:</td>
			<td colspan="3">{$manager.manager_name}</td>
		    </tr>
		    {/if}
		    <tr>
			<td align="right">E-Mail:</td>
			<td colspan="3">{if $customer.email!=''}{mailto address=$customer.email}{/if}</td>
		    </tr>
		    <tr><td colspan="4">&nbsp;</td></tr>
		</table>
	    </div>
	    <!--
	    <div id="contact">
		<table class="ui-widget ui-corner-top" width="75%" align="center" cellspacing="0" rules="all" style="border: solid 1px #000000;">
		    <thead class="ui-widget-header">
			<tr>
			    <th>#</th>
			    <th>ФИО</th>
			    <th>Должность</th>
			    <th>Телефон</th>
			    <th>E-Mail</th>
			    <th>Примечание</th>
			</tr>
		    </thead>
		    <tbody>
		    {foreach from=$contacts item=contact name=contacts}
			<tr>
			    <td align="center">{$smarty.foreach.contacts.iteration}</td>
			    <td>{$contact.contact_name}</td>
			    <td>{$contact.post}</td>
			    <td>{$contact.phone_number}</td>
			    <td>{if $contact.email}{mailto address=$contact.email}{else}&mdash;{/if}</td>
			    <td>{$contact.note}</td>
			</tr>
		    {foreachelse}
			<tr><td align="center" colspan="7"><i>контактов не найдено</i></td></tr>
		    {/foreach}
		    </tbody>
		</table>
	    </div>
	-->
	    <!--
	    <div id="bank">

		<table width="70%">
		    <tr>
			<th>&nbsp;</th>
			<th colspan="2">Реквизиты</th>
		    </tr>
		    <tr>
			<td rowspan="8">
			    {if not empty ($customer.legal_home)}
			    <p>
				<span>Юридический адрес:</span><br/>
				{$customer.legal_index}, {$customer.legal_region}, {$customer.legal_city}<br/>
				{$customer.legal_street}, д.{$customer.legal_home}{if $customer.legal_litera!=''}-{$customer.legal_litera}{/if}{if not empty($customer.legal_office)}, оф.{$customer.legal_office}{/if}
			    </p>
			    {/if}
			    {if not empty($customer.actual_home)}
			    <p>
				<span>Фактический адрес:</span><br/>
				{$customer.actual_index}, {$customer.actual_region}, {$customer.actual_city}<br/>
				{$customer.actual_street}, д.{$customer.actual_home}{if $customer.actual_litera!=''}-{$customer.actual_litera}{/if}{if not empty($customer.actual_office)}, оф.{$customer.actual_office}{/if}
			    </p>
			    {/if}
			    {if not empty($customer.postal_home)}
			    <p>
				<span>Почтовый адрес:</span><br/>
				{$customer.postal_index}, {$customer.postal_region}, {$customer.postal_city}<br/>
				{$customer.postal_street}, д.{$customer.postal_home}{if $customer.postal_litera!=''}-{$customer.postal_litera}{/if}{if not empty($customer.postal_office)}, оф.{$customer.postal_office}{/if}
			    </p>
			    {/if}
			</td>
			{if not empty($customer.inn)}
			<td align="right">ИНН:</td>
			<td>{$customer.inn}</td>
			{else}
			<td colspan="2">&nbsp;</td>
			{/if}
		    </tr>
		    {if not empty($customer.kpp)}
		    <tr>
			<td align="right">КПП:</td>
			<td>{$customer.kpp}</td>
		    </tr>
		    {/if}
		    {if not empty($customer.okpo)}
		    <tr>
			<td align="right">ОКПО:</td>
			<td>{$customer.okpo}</td>
		    </tr>
		    {/if}
		    {if not empty($customer.okonh)}
		    <tr>
			<td align="right">ОКОНХ:</td>
			<td>{$customer.okonh}</td>
		    </tr>
		    {/if}
		    {if not empty($customer.bik)}
		    <tr>
			<td align="right">БИК:</td>
			<td>{$customer.bik}</td>
		    </tr>
		    {/if}
		    {if not empty($customer.bank)}
		    <tr>
			<td align="right">БАНК:</td>
			<td>{$customer.bank|sslash|escape}</td>
		    </tr>
		    {/if}
		    {if not empty($customer.current_account)}
		    <tr>
			<td align="right">Р/С:</td>
			<td>{$customer.current_account}</td>
		    </tr>
		    {/if}
		    {if not empty($customer.korr_account)}
		    <tr>
			<td align="right">К/С:</td>
			<td>{$customer.korr_account}</td>
		    </tr>
		    {/if}
		</table>
	    </div>
	-->
	    {if $services|@count>0}
	    <div id="services">
		<script type="text/javascript">
		<!--{literal}
		$(document).ready
		(
		    function()
		    {
			var service_qs = '';

			$('table#detail-grid')
			    .jqGrid
			    ({
				datatype: 'json',
				pager:	'detail-grid-pager',
				colNames:	['ID','Номер','Назначение','Продолжительность','Стоимость','Дата','Направление'],
				colModel:
				[
				    {name:'id',hidden:true},
				    {name:'src',sortable:false},
				    {name:'dst',sortable:false},
				    {name:'duration',sortable:false},
				    {name:'cost',sortable:false},
				    {name:'date',sortable:false},
				    {name:'dst_name',sortable:false}
				],
				rowNum:	100
			    })
			    .setGridWidth(760)
			    .setGridHeight(270);

			$('div#detail').dialog
			(
			    'option',
			    {
				title:	'Детализация',
				width:	800,
				height:	400,
				resizeStop:	function(e,ui) { $('table#detail-grid').setGridHeight(ui.size['height']-130).setGridWidth(ui.size['width']-40); }
			    }
			);

			$('input:button#detail-show').click
			(
			    function()
			    {
				service_qs = '';

				$('input:checkbox.service-item').each(function(){if($(this).attr('checked')){service_qs+='&service_id[]='+$(this).val();}});

				if ( service_qs )
				{
				    $('div#detail')
					.dialog('open')
					.find('table#detail-grid')
					    .setGridParam({url: 'user-detail.php?'+service_qs })
					    .trigger('reloadGrid');
				}
			    }
			);

			$('input:button#set-date').click
			(
			    function()
			    {
				if ( service_qs )
				{
				    $('table#detail-grid')
					.setGridParam({ url: 'user-detail.php?'+service_qs+'&date_start='+$('input:text#detail-start').val()+'&date_stop='+$('input:text#detail-end').val() })
					.trigger('reloadGrid');
				}
			    }
			);

			$('input:button#download-csv').click
			(
			    function()
			    {
				if ( service_qs )
				{
				    window.location.href = 'user-detail.php?csv=yes&in_win=yes'+service_qs+'&date_start='+$('input:text#detail-start').val()+'&date_stop='+$('input:text#detail-end').val();
				}
			    }
			);
		    }
		);
		{/literal}-->
		</script>

		<div class="dialog" id="detail">
		    <table id="detail-grid"></table>
		    <div id="detail-grid-pager"></div>
		    <center>Период с <input type="text" class="date" id="detail-start"/> по <input type="text" class="date" id="detail-end"/>&nbsp;<input type="button" id="set-date" value="&rarr;"/>&nbsp;<input type="button" id="download-csv" value="Скачать CSV"/></center>
		</div>

		<div class="tabs">
		    <ul>
			{foreach from=$services item=executive key=executive_id}
			<li><a href="#executive-id{$executive_id}">{$services[$executive_id][0].executive_name|sslash}</a></li>
			{/foreach}
		    </ul>

		    {foreach from=$services item=executive key=executive_id}
		    <div id="executive-id{$executive_id}">
			<table class="ui-widget" cellspacing="0" width="90%" rules="all">
			    <thead class="ui-widget-header">
				<tr>
				    <th rowspan="2">&nbsp;</th>
				    <th rowspan="2">#</th>
				    <th rowspan="2">Наименование</th>
				    <th rowspan="2">Кол-во</th>
				    <th rowspan="2">Стоимость</th>
				    <th rowspan="2">Ежемесячная</th>
				    <th colspan="2">Дата</th>
				    <th colspan="2">Телефон</th>
				    <th rowspan="2">Начисления<br/><small>(за прошлый месяц)</small></th>
				</tr>
				<tr>
				    <th>начала</th>
				    <th>окончания</th>
				    <th>Номер</th>
				    <th>Тариф</th>
				</tr>
			    </thead>
			    <tbody>
			    {foreach from=$services[$executive_id] item=service name=service}
				<tr {if $service.completed==1}class="ui-state-disabled"{/if}>
				    <td align="center"><input type="checkbox" id="service-{$service.id}" class="service-item" value="{$service.id}" {if $service.service_name_id!=3 && $service.service_name_id!=30}disabled{/if}/></td>
				    <td>{$smarty.foreach.service.iteration}</td>
				    <td><label for="service-{$service.id}">{$service.service_name}</label></td>
				    <td align="center">{$service.quantity}</td>
				    <td align="center">{$service.cost|string_format:'%0.2f'}</td>
				    <td align="center">{if $service.monthly==1}<img src="images/icons/tick_16.png"/>{else}<img src="images/icons/block_16.png"/>{/if}</td>
				    <td align="center">{$service.start_date|date_format:'%d.%m.%Y, %H:%M:%S'}</td>
				    <td align="center">{if $service.stop_date=='0000-00-00 00:00:00'}&mdash;{else}{$service.stop_date|date_format:'%d.%m.%Y, %H:%M:%S'}{/if}</td>
				    {if $service.service_name_id==3 or $service.service_name_id==30}
				    <td align="center">{$service.phone_number}</td>
				    <td align="center">{$service.rate_name}</td>
				    {else}
				    <td align="center" colspan="2">&mdash;</td>
				    {/if}
				    <td align="center">{$service.last_cost|string_format:'%0.2f'}</td>
				</tr>
			    {/foreach}
			    </tbody>
			</table>
		    </div>
		    {/foreach}
		</div>
		<input type="button" class="button" id="detail-show" value="Детализация"/>
	    </div>
	    {/if}
	    <!--
	    <div id="document">
		<table class="ui-widget" cellspacing="0" rules="all" style="border: solid 1px #000000;">
		    <thead class="ui-widget-header">
			<tr>
			    <th>Дата</th>
			    <th>Номер документа</th>
			    <th>Название документа</th>
			    <th>Файл</th>
			    <th>&nbsp;</th>
			</tr>
		    </thead>
		    <tbody class="ui-widget-content">
		    {foreach from=$docs_regular item=doc}
			{assign var="mime" value=$doc.filename|regex_replace:'/.+\.(.+)$/':'$1'|lower}
			<tr>
			    <td>{$doc.document_date|date_format:'%d.%m.%Y'}</td>
			    <td>{$doc.document_num}</td>
			    <td>{$doc.document_name}</td>
			    <td>
				<a href="/cgi-bin/dl.cgi?id={$doc.id}&rand={$smarty.now}">
				    {if $mime=='jpg' || $mime=='gif' || $mime=='png' || $mime=='bmp'}
				    <img src="images/icons/mimetypes/image.png" border="0"/>
				    {elseif $mime=='pdf'}
				    <img src="images/icons/mimetypes/pdf-document.png" border="0"/>
				    {elseif $mime=='txt'}
				    <img src="images/icons/mimetypes/txt.png" border="0"/>
				    {else}
				    <img src="images/icons/mimetypes/unknown.png" border="0"/>
				    {/if}
				    {$doc.filename}
				</a>
				<i>({math equation='x/1024' x=$doc.size format='%0.2f'} КБ)</i>
			    </td>
			</tr>
		    {foreachelse}
			<tr><td align="center" colspan="5"><i>документы не загружены</i></td></tr>
		    {/foreach}
		    </tbody>
		</table>
	    </div>
	-->
	    {if $docs|@count>0}
	    <div id="invoice">
		<div class="tabs">
		    <ul>
			{foreach from=$docs item=executive key=executive_id}
			<li><a href="#executive-id_{$executive_id}">{$docs[$executive_id][0].executive_name|sslash}</a></li>
			{/foreach}
		    </ul>

		{foreach from=$docs item=executive key=executive_id}
		    <div id="executive-id_{$executive_id}">
			<table class="ui-widget" cellspacing="0" rules="all" width="75%">
			    <thead class="ui-widget-header">
				<tr>
				    <th rowspan="2">Номер</th>
				    <th rowspan="2">Дата</th>
				    <th colspan="4">Документ</th>
				</tr>
				<tr>
				    <th>Счет</th>
				    <th>Акт</th>
				    <th>Счет-фактура</th>
				    <th>Детализация</th>
				</tr>
			    </thead>
			    <tbody>
			    {foreach from=$docs[$executive_id] item=doc}
				<tr>
				    <td align="center">{$doc.id}</td>
				    <td align="center">{$doc.date|date_format:'%d.%m.%Y'}</td>
				    <td align="center">{if not empty($doc.account)}<a href="files/{$doc.account}?rand={$smarty.now}" target="_blank">Скачать</a>{else}&mdash;{/if}</td>
				    <td align="center">{if not empty($doc.act)}<a href="files/{$doc.act}?rand={$smarty.now}" target="_blank">Скачать</a>{else}&mdash;{/if}</td>
				    <td align="center">{if not empty($doc.invoice)}<a href="files/{$doc.invoice}?rand={$smarty.now}" target="_blank">Скачать</a>{else}&mdash;{/if}</td>
				    <td align="center">{if not empty($doc.detail)}<a href="files/{$doc.detail}?rand={$smarty.now}" target="_blank">Скачать</a>{else}&mdash;{/if}</td>
				</tr>
			    {/foreach}
			    </tbody>
			</table>
		    </div>
		{/foreach}
		</div>
	    </div>
	    {/if}
	</div>
    </body>
</html>
